<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>故障报修-云校通-教师</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
</head>
<body ontouchstart>
	<div class="weui_tab tab-bottom">
		<div class="weui-header bg-blue"> 
			<h1 class="weui-header-title">故障报修记录</h1>
			<div class="weui-header-right"><a href="<%=basePath %>/ls/fail/repaire/add" class="icon icon-36 f-white"> 添加</a></div> 
		</div>
		<div class="weui_tab_bd">
	        <div class="weui_tab" id="tab4">
	            <div class="weui_navbar">
	                <div class="weui_navbar_item ">
	                    待维修
	                </div>
	                <div class="weui_navbar_item" id="repairedList">
	                    已维修
	                </div>
	            </div>
	            <div class="weui_tab_bd">
			        <div class="weui_tab_bd_item">
			            <!--选项内容开始-->
				        <div class="weui_panel">
				            <div class="weui_panel_bd">
				                <div class="weui_media_box weui_media_small_appmsg">
				                    <div class="weui_cells weui_cells_access" id="repaireListTable">
				                        
				                    </div>
				                    
				                    <div class="dropload-down">
									    <div class="loadData dropload-hasData">点击加载更多数据...</div>
									</div>
				                </div>
				            </div>
				        </div>
			            <!--选项内容结束-->
			        </div>
			        <div class="weui_tab_bd_item">
			            <!--选项二内容-->
			            <div class="weui_panel">
				            <div class="weui_panel_bd">
				                <div class="weui_media_box weui_media_small_appmsg">
				                    <div class="weui_cells weui_cells_access" id="repairedListTable">
				                        
				                    </div>
				                    <div class="dropload-down">
									    <div class="loadData dropload-hasData">点击加载更多数据...</div>
									</div>
				                </div>
				            </div>
				        </div>
			            <!--End选项二内容-->
			        </div>
	            </div>
	        </div>
		</div>
	</div>
<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>
<script>
	var isLoadRepairedList = false;
	var dPage = 1,dRows = 5,yPage = 1, yRows = 5;
	var teaId = "${user.teacher.id}";
	$(function() {
		$('#tab4').tab({
			defaultIndex: 0,
			activeClass: "tab-blue "
		});
		$("#repairedList").click(function() {
			if(!isLoadRepairedList){
				var param = {
					page: yPage,
					rows: yRows,
					repaireStatus: '000'
				}
				parseInt("${isRepaire}") == 1 ? param.repaireId = teaId : param.repairId = teaId;
				loadItem(param, "repairedListTable");
			}
		})
		$(".dropload-down").on("click", ".dropload-hasData", function() {
			var id = $(this).closest(".weui_tab_bd_item").find(".weui_cells").attr("id");
			var param = {};
			if(id == 'repaireListTable') {
				param.page = dPage;
				param.rows = dRows;
				param.repaireStatus = '001';
				dPage+=1;
			}else {
				param.page = yPage;
				param.rows = yRows;
				param.repaireStatus = '000';
				yPage+=1;
			}
			parseInt("${isRepaire}") == 1 ? param.repaireId = teaId : param.repairId = teaId;
			loadItem(param, id);
		});
		var param = {
			page: dPage,
			rows: dRows,
			repaireStatus: '001'
		}
		dPage+=1;
		parseInt("${isRepaire}") == 1 ? param.repaireId = teaId : param.repairId = teaId;
		loadItem(param, "repaireListTable");
	});
	function loadItem(param, id) {
		$.ajax({
			url: basePath + '/ls/fail/repaire/page/query',
			type: 'post',
			dataType: 'json',
			data: param,
			success: function(data) {
				var html = "";
				if(data.rows.length == 0 || param.page*param.rows >= data.total) {// 如果没有数据
            		 $("#" + id).closest(".weui_tab_bd_item").find('.loadData').removeClass("dropload-hasData").addClass("dropload-noData").html("没有更多数据了");
                }
				for(var i in data.rows) {
					var itm = data.rows[i];
					html += '<a class="weui_cell" href="<%=basePath %>/ls/fail/repaire/detail/'+itm.id+'">\
                        <div class="weui_cell_bd weui_cell_primary">\
                    		<h4 class="weui_media_title f-blue">报修人：'+itm.repairName+'</h4>\
                    		<p class="weui_media_desc" style="padding-top: 10px;">故障类别：'+itm.repairType+'</p>\
                    		<p class="weui_media_desc" style="margin-top: 5px;">报修时间：'+getTime(itm.repairTime,"yyyy-MM-dd hh:mm")+'</p>\
                		</div>\
                		<span class="weui_cell_ft"></span>\
            		</a>';
				}
				$("#" + id).append(html);
			}
		});
	}
</script>
</body>
</html>